﻿using System;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using FastReport;

namespace PuanYonetimi
{
    public partial class frmMain : XtraForm
    {
        Senkronizasyon senk = new Senkronizasyon();

        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            if (Program.Session[Settings.AktarimDurumu].ToString() == "START")
            {
                barButtonItem10.LargeImageIndex = 9;
            }
            else
            {
                barButtonItem10.LargeImageIndex = 10;
            }
            SenkStat();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmPuanYukleme frm = new frmPuanYukleme())
            {
                frm.ShowDialog();
            }
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmPuanSilme frm = new frmPuanSilme())
            {
                frm.ShowDialog();
            }
        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmPuanListe frm = new frmPuanListe())
            {
                frm.ShowDialog();
            }
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmHediyecekiVerme frm = new frmHediyecekiVerme())
            {
                frm.ShowDialog();
            }
        }

        private void barButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmCekListesi frm = new frmCekListesi())
            {
                frm.ShowDialog();
            }
        }

        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmMagaza frm = new frmMagaza())
            {
                frm.ShowDialog();
            }
        }

        private void barButtonItem7_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (frmPuanTanitim frm = new frmPuanTanitim())
            {
                frm.ShowDialog();
            }
        }

        private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                CashRegister reg = new CashRegister();
                reg.PuanBilgisiGonder();
                Cursor.Current = Cursors.Default;
                MessageBox.Show("Gönderildi !");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hata Oluştu !\r\n" + ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void barButtonItem9_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string fileName = Application.StartupPath + "\\CekDizayn.dsx";
            Report rp = null;
            if (File.Exists(fileName))
            {
                rp = Report.FromFile(fileName);
            }
            else
            {
                rp = new Report();
                rp.FileName = fileName;
            }

            BindingSource bs = new BindingSource();
            bs.DataSource = new PrintDesing();
            rp.RegisterData(bs, "Document", 10);
            rp.GetDataSource("Document").Enabled = true;

            DesignForm frm = new DesignForm();
            frm.Report = rp;
            frm.ShowDialog(this);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            senk.CariAktar();
            senk.HareketPuanVer();
        }

        private void barButtonItem10_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SenkStat();
        }

        private void SenkStat()
        {
            if (barButtonItem10.LargeImageIndex == 9)
            {
                barButtonItem10.LargeImageIndex = 10;
                barButtonItem10.Caption = "Aktarımı Durdur";
                ribbonPageGroup5.Text = "Çalışıyor..";
                timer1.Start();
                timer1.Enabled = true;
                Program.Session[Settings.AktarimDurumu] = "START";
            }
            else
            {
                barButtonItem10.LargeImageIndex = 9;
                barButtonItem10.Caption = "Aktarımı Başlat";
                ribbonPageGroup5.Text = "Durduruldu !";
                timer1.Stop();
                timer1.Enabled = false;
                Program.Session[Settings.AktarimDurumu] = "STOP";
            }
        }
    }
}
